package band.wukong.practice.javase.core.io.stream.filterstream;

import java.io.*;

/**
 * Desc:
 * Author: sunjs
 * Date: 2009-11-16 10:59:45
 */
public class TestDataStream {
    static final String FILE_OUT = "E:\\workspace\\TestJava\\src\\com\\jsun\\javase\\io\\doc\\out.txt";

    public static void main(String[] args) throws Exception {
        FileOutputStream out1 = new FileOutputStream(FILE_OUT);
        BufferedOutputStream out2 = new BufferedOutputStream(out1);
        DataOutputStream out = new DataOutputStream(out2);

        out.writeByte(-12);
        out.writeLong(12);
        out.writeChar('1');
        out.writeUTF("好");
        out.close();

        InputStream in1 = new FileInputStream(FILE_OUT);
        BufferedInputStream in2 = new BufferedInputStream(in1);
        DataInputStream in = new DataInputStream(in2);
        System.out.println("in.readByte() = " + in.readByte());
        System.out.println("in.readLong() = " + in.readLong());
        System.out.println("in.readChar() = " + in.readChar());
        System.out.println("in.readUTF() = " + in.readUTF());
    }

    /*
        注意：
            实际上，writeUTF8()和readUTF8()使用的是适合于Java的UTF-8变体，详见JDK文档。

            DataInputStream应该和DataOutputStream类配套使用。
            也就是说，用DataInputStream读取由DataOutputStream写出的数据，才能保证数据的正确性。
     */
}
